package com.zzh.wsss.mapper;

import com.zzh.wsss.pojo.User;
import com.zzh.wsss.pojo.UserMsg;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface UserOperateMapper {

    List<User> getPassword(@Param("username") String username);

    User getUserMag(@Param("username") String username);

    @Select("select id from user where username=#{username}")
    User getUserId(@Param("username") String username);

    @Update("update user set headportrait=#{filename} where username=#{username}")
    void SetUserHeadportrait(@Param("username") String username, @Param("filename") String filename);

    @Update("update user set nickname=#{nickname} where username=#{username}")
    void SetUserNickname(@Param("username") String username,@Param("nickname") String nickname);

    @Update("update user set password=#{password} where username=#{username}")
    void SetUserPassword(@Param("username") String username,@Param("password") String newpassword);

    @Select("select count(*) from user where job_id=#{jobId}")
    Integer getJobUserNum(@Param("jobId") Integer id);

    @Update("update user set job_id=#{jobId} where username=#{username}")
    void updataUserJob(@Param("username") String username,@Param("jobId") Integer jobId);

    @Update("update user set job_id=null where username=#{username}")
    void updataUserJobNull(@Param("username") String username);

    @Select("select user.id,username,nickname,job_id,job_name from user left join job on user.job_id= job.id")
    List<UserMsg> getUsersMsg();

    @Select("select user.id,username,nickname,job_id,job_name from user left join job on user.job_id= job.id where username like '%${search}%'")
    List<UserMsg> getGivenUsersMsg(@Param("search") String search);

    @Insert("insert into user (username,password) values (#{username},#{password})")
    void addUser(@Param("username") String username,@Param("password") String password);

    @Delete("delete from user where id = #{id}")
    void deleteUser(@Param("id") Integer parseInt);

    @Select("select username from user where job_id=#{jobId}")
    List<String> getJobUserMsg(@Param("jobId") Integer id);

}
